package com.villaday.idf.activity3;

import androidx.swiperefreshlayout.widget.SwipeRefreshLayout;
import androidx.recyclerview.widget.RecyclerView;
import androidx.appcompat.widget.Toolbar;
import android.view.View;
import android.widget.ImageButton;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.bigkoo.pickerview.builder.TimePickerBuilder;
import com.bigkoo.pickerview.listener.OnTimeSelectListener;
import com.bigkoo.pickerview.view.TimePickerView;
import com.villaday.idf.R;
import com.villaday.idf.base.BaseActivity;
import com.villaday.idf.custom.CircleTextView;
import com.villaday.idf.util.LogeUtil;
import com.villaday.idf.util.ToolBarUtil;

import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.Locale;

import butterknife.BindView;
import butterknife.OnClick;

public class ShopSelectTimeActivity extends BaseActivity {


    @BindView(R.id.toolbar_iconBack)
    ImageButton toolbarIconBack;
    @BindView(R.id.toolbar_iconTitle)
    TextView toolbarIconTitle;
    @BindView(R.id.toolbar_iconNext)
    ImageButton toolbarIconNext;
    @BindView(R.id.toolbar_iconCartDot)
    CircleTextView toolbarIconCartDot;
    @BindView(R.id.toolbar_iconLine)
    View toolbarIconLine;
    @BindView(R.id.toolbar_icon)
    Toolbar toolbarIcon;
    @BindView(R.id.tv_install_app)
    TextView tvInstallApp;
    @BindView(R.id.tv_inquire_start_time)
    TextView tvInquireStartTime;
    @BindView(R.id.tv_inquire_end_time)
    TextView tvInquireEndTime;
    @BindView(R.id.tv_select_btn)
    TextView tvSelectBtn;
    @BindView(R.id.ll_select_layout)
    LinearLayout llSelectLayout;
    @BindView(R.id.rv)
    RecyclerView rv;
    @BindView(R.id.srl)
    SwipeRefreshLayout srl;

    @Override
    protected int getViewResId() {
        return R.layout.activity_customer_behavior;
    }


    @Override
    protected void init() {
        super.init();
        llSelectLayout.setVisibility(View.VISIBLE);
        ToolBarUtil.init(toolbarIcon, "客户行为", new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                onBackPressed();
            }
        });

    }


    @OnClick({R.id.tv_install_app, R.id.tv_inquire_start_time, R.id.tv_inquire_end_time, R.id.tv_select_btn})
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.tv_install_app:   //安装App
                break;
            case R.id.tv_inquire_start_time:   //开始时间
                break;
            case R.id.tv_inquire_end_time:   //结束时间
                break;
            case R.id.tv_select_btn:   //查询
                break;
        }

    }



    private void initStartTime() {
        Calendar selectedDate = Calendar.getInstance();
        int year = selectedDate.get(Calendar.YEAR);    //获取年
        int month = selectedDate.get(Calendar.MONTH) + 1;   //获取月份，0表示1月份
        int day = selectedDate.get(Calendar.DAY_OF_MONTH);    //获取当前天数
        int first = selectedDate.getActualMinimum(selectedDate.DAY_OF_MONTH);    //获取本月最小天数
        int last = selectedDate.getActualMaximum(selectedDate.DAY_OF_MONTH);    //获取本月最大天数
        int time = selectedDate.get(Calendar.HOUR_OF_DAY);       //获取当前小时
        int min = selectedDate.get(Calendar.MINUTE);          //获取当前分钟
        int xx = selectedDate.get(Calendar.SECOND);          //获取当前秒
        LogeUtil.e("loge", "");
//        Calendar startDate = Calendar.getInstance();
//        startDate.set(2013, 0, 1);
        Calendar endDate = Calendar.getInstance();
        endDate.set(year, month - 1, day);
        //正确设置方式 原因：注意事项有说明


        TimePickerView pvTime = new TimePickerBuilder(this, new OnTimeSelectListener() {
            @Override
            public void onTimeSelect(Date date, View v) {//选中事件回调
                SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd", Locale.CHINA);
//                tvStartTime.setText(format.format(date));
//                initEndTime(format.format(date));
            }
        }).setType(new boolean[]{true, true, true, false, false, false})// 默认全部显示
                .setCancelText("取消")//取消按钮文字
                .setSubmitText("确定")//确认按钮文字
                .setContentTextSize(18) //滚轮文字大小
                .setTitleSize(18)//标题文字大小
                .setTitleText("请选择开始时间")//标题文字
                .setOutSideCancelable(true)//点击屏幕，点在控件外部范围时，是否取消显示
                .isCyclic(false)//是否循环滚动
                .setTitleColor(getResources().getColor(R.color.colorRed))//标题文字颜色
                .setSubmitColor(getResources().getColor(R.color.colorRed))//确定按钮文字颜色
                .setCancelColor(getResources().getColor(R.color.colorRed))//取消按钮文字颜色
                .setTitleBgColor(getResources().getColor(R.color.colorGrayBg))//标题背景颜色 Night mode
                .setBgColor(getResources().getColor(R.color.colorWhite))//滚轮背景颜色 Night mode
                .setDate(selectedDate)// 如果不设置的话，默认是系统时间*/
                .setRangDate(null, endDate)//起始终止年月日设定
                .setLabel("年", "月", "日", "时", "分", "秒")//默认设置为年月日时分秒
                .isCenterLabel(false) //是否只显示中间选中项的label文字，false则每项item全部都带有label。
                .isDialog(false)//是否显示为对话框样式
                .build();
        pvTime.show();
    }


    private void initEndTime(String date) {
        Calendar selectedDate = Calendar.getInstance();

        String[] var = date.split("-");
        Calendar startDate = Calendar.getInstance();
        startDate.set(Integer.parseInt(var[0]), Integer.parseInt(var[1]) - 1, Integer.parseInt(var[2]) - 1);
//        Calendar endDate = Calendar.getInstance();
//        endDate.set(year, month-1, day);
        //正确设置方式 原因：注意事项有说明


        TimePickerView pvTime = new TimePickerBuilder(this, new OnTimeSelectListener() {
            @Override
            public void onTimeSelect(Date date, View v) {//选中事件回调
                SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd", Locale.CHINA);
//                tvEndTime.setText(format.format(date));
            }
        }).setType(new boolean[]{true, true, true, false, false, false})// 默认全部显示
                .setCancelText("取消")//取消按钮文字
                .setSubmitText("确定")//确认按钮文字
                .setContentTextSize(18) //滚轮文字大小
                .setTitleSize(18)//标题文字大小
                .setTitleText("请选择结束时间")//标题文字
                .setOutSideCancelable(false)//点击屏幕，点在控件外部范围时，是否取消显示
                .isCyclic(false)//是否循环滚动
                .setTitleColor(getResources().getColor(R.color.colorRed))//标题文字颜色
                .setSubmitColor(getResources().getColor(R.color.colorRed))//确定按钮文字颜色
                .setCancelColor(getResources().getColor(R.color.colorRed))//取消按钮文字颜色
                .setTitleBgColor(getResources().getColor(R.color.colorGrayBg))//标题背景颜色 Night mode
                .setBgColor(getResources().getColor(R.color.colorWhite))//滚轮背景颜色 Night mode
                .setDate(selectedDate)// 如果不设置的话，默认是系统时间*/
                .setRangDate(startDate, selectedDate)//起始终止年月日设定
                .setLabel("年", "月", "日", "时", "分", "秒")//默认设置为年月日时分秒
                .isCenterLabel(false) //是否只显示中间选中项的label文字，false则每项item全部都带有label。
                .isDialog(false)//是否显示为对话框样式
                .build();
        pvTime.show();
    }

}
